setTimeout(function(){
	
	$("#name").rules("add",{
		remote: {
			url: 'qz/channel/checkName', 
			type: "get",
			data: {"id":""},
			dataType: "json", 
			dataFilter:function(data,type){
				return data=="false"?false:true;
			}
		}, 
		messages: {remote: "该机构已添加"}
	});
} , parseInt(Math.random() * 1000));

setTimeout(function(){
	
	$("#code").rules("add",{
		remote: {
			url: 'qz/channel/checkCode', 
			type: "get",
			data: {"id":""},
			dataType: "json", 
			dataFilter:function(data,type){
				return data=="false"?false:true;
			}
		}, 
		messages: {remote: "该编码已添加"}
	});
} , parseInt(Math.random() * 1000));


var app = angular.module('qzchannelApp', []);
var reslist;
var code;
app.controller('qzchannelController', function($scope, $http) {
	$scope.qzchannelApp;
	var busid={};
	$scope.view=function(){
		$http.get('qz/business/getAll?status=2').success(function(response){
			$scope.businessList=response.data;
        });
		
	}
	
	$scope.view();
	
	$scope.vername=function(name){
		$http.get('qz/channel/getAll/', {params: {name:name}}).success(function(response){
			$scope.nameList=response.data;
//			console.log($scope.nameList[0].name);
			if($scope.nameList.length == 0) {
				reslist = '';
			}else {
				reslist = $scope.nameList[0].name;
			}
		});
	}
	
	$scope.vercode=function(code){
		$http.get('qz/channel/getAll/', {params: {code:code}}).success(function(response){
			$scope.codeList=response.data;
//			console.log($scope.codeList[0].code);
			
		});
	}
	
	$scope.busclick=function(msg) {
		var id = [];
		$('input[name="bus"]:checked').each(function(){ 
			id.push($(this).val()); 
		});
		busid = id;
	}
	
	$scope.chSave=function(){
		if($("#myForm").valid()){
			var param = {
					name: $scope.qzChannel.name,
					code: $scope.qzChannel.code,
					memo: $scope.qzChannel.memo,
					busid: busid
			}
			$http.post('qz/channel/add/', param).success(function(){
				redirectUrl("manage/channel/","list.jsp");
			});
		}
//		if($scope.codeList == null) {
//			code = '';
//		}else {
//			code = getQueryString("code");
//			console.log(code);
//		}
//		if($scope.qzChannel == null) {
//			$("#myForm").valid();
//		}else {
//			if($scope.qzChannel.name != reslist && $scope.qzChannel.code != code) {
//				if($("#myForm").valid()){
//					var param = {
//							name: $scope.qzChannel.name,
//							code: $scope.qzChannel.code,
//							memo: $scope.qzChannel.memo,
//							busid: busid
//					}
//					$http.post('qz/channel/add/', param).success(function(){
//						redirectUrl("manage/channel/","list.jsp");
//					});
//				}
//			}
//		}
	}
	
	$scope.chReset=function(){
		$scope.master = {name: "", code: "", memo: ""};
		$scope.qzChannel=angular.copy($scope.master);
		$scope.view();
	}
	
	$scope.menuCancle=function(){
		redirectUrl("manage/channel/","list.jsp");
	}
});
